<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->

<!--      <el-form-item label="产品名称" prop="productName">-->
<!--        <el-input-->
<!--          v-model="queryParams.productName"-->
<!--          placeholder="请输入产品名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="评价状态：" prop="isComment">-->
<!--        <el-select v-model="queryParams.isComment" placeholder="请选择评论状态" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.is_no"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['business:orderitem:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['business:orderitem:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['business:orderitem:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['business:orderitem:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="orderitemList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="订单项ID" align="center" prop="orderItemId" />
      <el-table-column label="订单编号" align="center" prop="orderNo" />
<!--      <el-table-column label="产品ID" align="center" prop="productId" />-->
<!--      <el-table-column label="购买东西的详细信息" align="center" prop="info" />-->
      <el-table-column label="产品个数" align="center" prop="payNum" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="产品图片" align="center" prop="image" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.image" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="产品价格" align="center" prop="price" />
      <el-table-column label="商品总金额" align="center" prop="totalPrice" />
      <el-table-column label="评论状态" align="center" prop="isComment">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_no" :value="scope.row.isComment"/>
        </template>
      </el-table-column>
      <el-table-column label="商品类型" align="center" prop="productType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.product_type" :value="scope.row.productType"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="退款状态" align="center" prop="refundStatus" />-->
<!--      <el-table-column label="退款原因" align="center" prop="refundReason" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['business:orderitem:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            @click="viewupdate(scope.row)"
          >查看</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['business:orderitem:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单明细项对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单order_no" />
        </el-form-item>
<!--        <el-form-item label="购买东西的详细信息" prop="info">-->
<!--          <el-input v-model="form.info" placeholder="请输入购买东西的详细信息" />-->
<!--        </el-form-item>-->
        <el-form-item label="购物车产品个数" prop="payNum">
          <el-input v-model="form.payNum" placeholder="请输入购物车产品个数" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="产品主图片路径" prop="image">
          <image-upload v-model="form.image"/>
        </el-form-item>
        <el-form-item label="产品价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入产品价格" />
        </el-form-item>
        <el-form-item label="商品总金额" prop="totalPrice">
          <el-input v-model="form.totalPrice" placeholder="请输入商品总金额" />
        </el-form-item>
        <el-form-item label="评价状态：" prop="isComment">
          <el-select v-model="form.isComment" placeholder="请选择评论状态">
            <el-option
              v-for="dict in dict.type.is_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="退款原因" prop="refundReason">-->
<!--          <el-input v-model="form.refundReason" placeholder="请输入退款原因" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="${comment}" prop="remark">-->
<!--          <el-input v-model="form.remark" placeholder="请输入${comment}" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrderitem, getOrderitem, delOrderitem, addOrderitem, updateOrderitem } from "@/api/business/orderitem";

export default {
  name: "Orderitem",
  dicts: ['is_no','product_type'],
  props: {
    orderNo: {
      type: String
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单明细项表格数据
      orderitemList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        productId: null,
        info: null,
        payNum: null,
        productName: null,
        image: null,
        price: null,
        userId: null,
        totalPrice: null,
        isComment: null,
        productType: null,
        refundStatus: null,
        refundReason: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderNo: [
          { required: true, message: "订单order_no不能为空", trigger: "blur" }
        ],
        productId: [
          { required: true, message: "产品ID不能为空", trigger: "blur" }
        ],
        payNum: [
          { required: true, message: "购物车产品个数不能为空", trigger: "blur" }
        ],
        productName: [
          { required: true, message: "产品名称不能为空", trigger: "blur" }
        ],
        image: [
          { required: true, message: "产品主图片路径不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "产品价格不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "用户Id不能为空", trigger: "blur" }
        ],
        totalPrice: [
          { required: true, message: "商品总金额不能为空", trigger: "blur" }
        ],
        isComment: [
          { required: true, message: "评论状态： 1 未评价  0 已评价不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单明细项列表 */
    getList() {
      this.loading = true;
      this.queryParams.orderNo = this.orderNo;
      listOrderitem(this.queryParams).then(response => {
        this.orderitemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderItemId: null,
        orderNo: null,
        productId: null,
        info: null,
        payNum: null,
        productName: null,
        image: null,
        price: null,
        userId: null,
        totalPrice: null,
        isComment: null,
        productType: null,
        refundStatus: null,
        refundReason: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderItemId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单明细项";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderItemId = row.orderItemId || this.ids
      getOrderitem(orderItemId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单明细项";
      });
    },
    viewupdate(row) {
      this.reset();
      const orderItemId = row.orderItemId || this.ids
      getOrderitem(orderItemId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看订单明细项";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderItemId != null) {
            updateOrderitem(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderitem(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderItemIds = row.orderItemId || this.ids;
      this.$modal.confirm('是否确认删除订单明细项编号为"' + orderItemIds + '"的数据项？').then(function() {
        return delOrderitem(orderItemIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/orderitem/export', {
        ...this.queryParams
      }, `orderitem_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
